package com.zfx.redis.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

/**
 * @description:
 * @author: zheng_fx
 * @create: 2021-08-28 22:22
 */
@RestController
public class RedisController {

    private final static String FLAGKEY = "pay:info:flag";
    private final static Boolean Yantrue = true;
    private final static Boolean Yanfalse = false;


    @Autowired
    StringRedisTemplate stringRedisTemplate;

    //redis的路径   FLAGKEY  flag值
    @GetMapping("/test/{flag}")
    public String test(@PathVariable String flag) {

        //if (StringUtils.isEmpty(flag)) {
        if ("1".equals(flag)) {
            //kong
            stringRedisTemplate.opsForValue().set(FLAGKEY, String.valueOf(Yantrue));
            System.out.println("空+++flag"+Yantrue);
        }else {
            stringRedisTemplate.opsForValue().set(FLAGKEY, String.valueOf(Yanfalse));
            System.out.println("bu空+++flag"+Yanfalse);
        }
    //    stringRedisTemplate.opsForValue().set(FLAGKEY, flag);
        return "当前redis中缓存：" + stringRedisTemplate.opsForValue().get(FLAGKEY);
    }
}
